﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyEncoder
{
    /// <summary>
    /// 创建一个加密类
    /// </summary>
    public class VEncoder
    {
        /// <summary>
        /// 明文
        /// </summary>
        public string plainText { get; set; }
        /// <summary>
        /// 密钥
        /// </summary>
        public string key { get; set; }
        /// <summary>
        /// 密文
        /// </summary>
        public string cipher { get; set; }
        /// <summary>
        ///加密函数
        /// </summary>
        /// <returns></returns>
        public void encryption()
        {
            //创建两个数组分别存储密钥和密文对应的int值
            List<int> numkey= new List<int>();
            List<int> numCipherText = new List<int>();
            //密钥int值组成的数组
            for (int i = 0; i < key.Length ; i++)
            {
                int numKey = key[i] - 'a';
                numkey.Add(numKey);
            }
            //密文
            for( int i = 0 ; i < plainText.Length; i++ )
            {
                int numPlainText= plainText[i] - 'a';
                int n = i % key.Length;
                numCipherText.Add( numPlainText + numkey[n]);
                char m = Convert.ToChar(numCipherText[i]+97);
                cipher += m;
            }
            Console.WriteLine(cipher);           
        }
    }
}
